package com.jm.controller;

import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSON;
import com.jm.domain.ResponseResult;
import com.jm.domain.entity.Category;
import com.jm.domain.vo.CategoryVo;
import com.jm.domain.vo.ExcelCategoryVo;
import com.jm.enums.AppHttpCodeEnum;
import com.jm.service.CategoryService;
import com.jm.utils.BeanCopyUtils;
import com.jm.utils.WebUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/content/category")
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    @GetMapping("/listAllCategory")
    public ResponseResult listAllCategory(){
        return categoryService.listAllCategory();
    }

    @PreAuthorize("@ps.hasPermission('content:category:export')")
    @GetMapping("/export")  
    public void export(HttpServletResponse response){
        categoryService.export(response);
    }

    @GetMapping("/list")
    public ResponseResult list(Integer pageNum,Integer pageSize,String name,String status){
        return categoryService.listCategory(pageNum,pageSize,name,status);
    }

    @PostMapping
    public ResponseResult save(@RequestBody Category category){
        return categoryService.saveCategory(category);
    }

    @GetMapping("/{id}")
    public ResponseResult getCategoryById(@PathVariable Long id){
        return categoryService.getCategoryById(id);
    }

    @PutMapping
    public ResponseResult update(@RequestBody Category category){
        return categoryService.updateCategory(category);
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable Long id){
        return categoryService.deleteCategory(id);
    }
}
